/**
 * Copyright &copy; 2012-2016 <a href="https://istep.lczyfz.com">Istep</a> All rights reserved.
 */
package com.lczyfz.istep.modules.scene.service;

import com.lczyfz.istep.common.persistence.Page;
import com.lczyfz.istep.common.service.CrudService;
import com.lczyfz.istep.modules.scene.dao.SceneVmTemplateDao;
import com.lczyfz.istep.modules.scene.entity.SceneCtfEnvironmentInstance;
import com.lczyfz.istep.modules.scene.entity.SceneEnvironmentInstance;
import com.lczyfz.istep.modules.scene.entity.SceneVmTemplate;
import com.lczyfz.istep.modules.sys.entity.User;
import com.lczyfz.istep.modules.sys.utils.UserUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 虚拟机模板管理Service
 * @author dh
 * @version 2017-04-06
 */
@Service
@Transactional(readOnly = true)
public class SceneVmTemplateService extends CrudService<SceneVmTemplateDao, SceneVmTemplate> {
	@Autowired
	private SceneEnvironmentInstanceService sceneEnvironmentInstanceService;
	@Autowired
	private SceneCtfEnvironmentInstanceService sceneCtfEnvironmentInstanceService;
	public SceneVmTemplate get(String id) {
		return super.get(id);
	}
	
	public List<SceneVmTemplate> findList(SceneVmTemplate sceneVmTemplate) {
		return super.findList(sceneVmTemplate);
	}
	
	public Page<SceneVmTemplate> findPage(Page<SceneVmTemplate> page, SceneVmTemplate sceneVmTemplate) {
		return super.findPage(page, sceneVmTemplate);
	}
	
	@Transactional(readOnly = false)
	public void save(SceneVmTemplate sceneVmTemplate) {
		super.save(sceneVmTemplate);
	}
	
	@Transactional(readOnly = false)
	public void delete(SceneVmTemplate sceneVmTemplate) {
		super.delete(sceneVmTemplate);
	}
	@Transactional(readOnly = false)
	public void insert(SceneVmTemplate sceneVmTemplate) {
		dao.insert(sceneVmTemplate);
	}
	public void preInsert(SceneVmTemplate preInfo) {

		User user = UserUtils.getUser();
		if (StringUtils.isNotBlank(user.getId())) {
			preInfo.setUpdateBy(user);
			preInfo.setCreateBy(user);
		}
		Date date=new Date();
		preInfo.setUpdateDate(date);
		preInfo.setCreateDate(date);

	}
	@Transactional(readOnly = false)
	public void  vmNetworkInsert (String vmTemplateId,String networkId,String environmentId)
	{
		dao.vmNetworkInsert(vmTemplateId, networkId, environmentId);
	}
	@Transactional(readOnly = false)
	public void  vmPortInsert (String vmTemplateId,String portId)
	{
		dao.vmPortInsert(vmTemplateId, portId);

	}
	@Transactional(readOnly = false)
	public void  vmSecurityGroupInsert (String vmTemplateId,String sgId)
	{
		dao.vmSecurityGroupInsert(vmTemplateId, sgId);

	}
	public List<SceneVmTemplate> findVMListByEnvironmentId(String DEL_FLAG_NORMAL,String id)
	{
		return dao.findVMListByEnvironmentId(DEL_FLAG_NORMAL,id);
	}
	public Page<SceneEnvironmentInstance> findVmMonitorPage(Page<SceneEnvironmentInstance> page,SceneEnvironmentInstance sceneEnvironmentInstance) {
		sceneEnvironmentInstance.setPage(page);
		page.setList(dao.findVmMonitorList(sceneEnvironmentInstance));
		return page;
	}
	public Page<SceneCtfEnvironmentInstance> findCtfVmMonitorPage(Page<SceneCtfEnvironmentInstance> page,SceneCtfEnvironmentInstance sceneCtfEnvironmentInstance) {
		sceneCtfEnvironmentInstance.setPage(page);
		page.setList(dao.findCtfVmMonitorList(sceneCtfEnvironmentInstance));
		return page;
	}
	public SceneVmTemplate viewResourceDetail(String id)
	{
		return dao.viewResourceDetail(id);
	}
	public SceneVmTemplate viewCtfResourceDetail(String id)
	{
		return dao.viewCtfResourceDetail(id);
	}
	@Transactional(readOnly = false)
	public void vmMonitorDelete(String instanceId,String vmTemplateId)
	{
		dao.vmMonitorDelete(instanceId,vmTemplateId);
	}

	public SceneVmTemplate findVmTemplateByName(String name,String DEL_FLAG_NORMAL)
	{
		return dao.findVmTemplateByName(name,DEL_FLAG_NORMAL);
	}


}